/**
 * 
 */
package com.huniu.analysis.colony;

import org.apache.log4j.Logger;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import com.huniu.links.exception.LinkProcessException;

/**
 * @author zandy (chenheng)
 *
 */
public abstract class AbstractBeeAnalyseImpl implements IBeeAnalyse {
	
	private static final Logger logger = Logger.getLogger(AbstractBeeAnalyseImpl.class);
	
	public String getCachedContent(String key,String cacheName) throws LinkProcessException {
		CacheManager singletonManager = CacheManager.create();
		logger.info("Get singleton cache manager : "
				+ singletonManager.getName());
		Cache cache = singletonManager.getCache(cacheName);
		logger.info("Get cache object : " + cache == null ? cache.getName() : null );
		Element element = cache.get(key);
		if ( element == null ) {
			throw new LinkProcessException("Hit url failure : " + key, null);
		}
		String content = (String) element.getValue();
		logger.info("Get emement({key=" + key + ",value=...}) from cache : "
				+ cache.getName());
		return content;
	} 
	
	public void analyse() {

	}

	public void run() {
		analyse();
	}

}
